Page({
  data: {
    date: {
      dayArr: ['week', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'sunday'],
      monthArr: ['january', 'February', 'march', 'april', 'may', 'june', 'july', 'August', 'September', 'October', 'November', 'December']
    },
    initializeSwitch: true, // 初始化开关
    allData: {
      todaySelect: {}
    }
  },
  onLoad(query) {
    let todayInfo = new Date();
    this.setData({
      // this.dayArr[Number(date.getDay())].toUpperCase()
      'date.day': this.data.date.dayArr[todayInfo.getDay()].toUpperCase(),
      'date.month': this.data.date.monthArr[todayInfo.getMonth()].toUpperCase(),
      'date.date': todayInfo.getDate()
    });
    let self = this;
    my.showLoading({
      content: '加载中...'
    });
    my.httpRequest({
      url: 'http://baobab.kaiyanapp.com/api/v4/tabs/selected',
      data: {
        num: 10
      },
      // method: 'GET',
      // dataType: 'json',
      // headers: {
      //   'Content-Type': 'json'
      // },
      success: function(res) {
        my.hideLoading();
        my.showToast({
          content: '加载成功',
          type: 'success',
          duration: '1500'
        });
        let todayArr = []
        for (let i = 1; i < 6; i++) {
          todayArr.push(JSON.parse(JSON.stringify(res.data.itemList[i])));
        }
        console.log('todayArr');
        console.log(todayArr);
        self.setData({
          initializeSwitch: false,
          'allData.todaySelect': todayArr
        });
        console.log('1+++++++++++++++++++++++++++++');
        console.log(res);
      },
      fail: function(res) {
        my.hideLoading();
        my.showToast({
          content: '数据加载成功',
          type: 'fail',
          duration: '1500'
        });
        console.log(res);
      }
    });
    // 页面加载
    console.info(`Page onLoad with query: ${JSON.stringify(query)}`);
  },
  onReady() {
    // 页面加载完成
  },
  onShow() {
    // 页面显示
  },
  onHide() {
    // 页面隐藏
  },
  onUnload() {
    // 页面被关闭
  },
  onTitleClick() {
    // 标题被点击
  },
  onPullDownRefresh() {
    // 页面被下拉
  },
  onReachBottom() {
    // 页面被拉到底部
  },
  onShareAppMessage() {
    // 返回自定义分享信息
    return {
      title: 'My App',
      desc: 'My App description',
      path: 'pages/index/index',
    };
  },
  filterTime(str) {
    return str.toString().padStart(2, 0);
  }
});
